import { describe } from '$lib';
import { Clock } from './clock';
import { log } from './log';
import { getPos3, move, onTile } from './pos3';
import { logVisible } from './render3';

export const Move3Action = (check) => (dx, dy, dz, delay) => (world, e) => {
  Clock.time[e] += delay;
  const { x, y, z } = getPos3(e);
  const x1 = x + dx;
  const y1 = y + dy;
  const z1 = z + dz;
  // TODO: if going up/down, and a creature is in the way, try to land near them instead of giving up
  const es = onTile(world, x1, y1, z1);

  if (check(world, es)) {
    move(world, e, x1, y1, z1);
  } else {
    let dsc;
    if (es.length === 0) {
      dsc = 'the unknown';
    } else {
      // const tgt = col[0];
      // dsc = describe(world, tgt);
    }
    logVisible(e, `${describe(world, e)} bumps into ${dsc}`);
  }
};
